<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
     <!-- <el-form-item label="预约单标识" prop="bookingOrderId">
        <el-input
          v-model="queryParams.bookingOrderId"
          placeholder="请输入预约单标识"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="预约用户—外键" prop="bookingOrderPid">
        <el-input
          v-model="queryParams.bookingOrderPid"
          placeholder="请输入预约用户—外键"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="技师—外键" prop="bookingOrderPers">
        <el-input
          v-model="queryParams.bookingOrderPers"
          placeholder="请输入技师—外键"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
    <!--  <el-form-item label="预约位置" prop="bookingOrderPath">
        <el-input
          v-model="queryParams.bookingOrderPath"
          placeholder="请输入预约位置"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
     <!-- <el-form-item label="服务类型" prop="bookingOrderType">
        <el-select v-model="queryParams.bookingOrderType" placeholder="请选择服务类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item> -->
     <!-- <el-form-item label="车牌号" prop="bookingOrderCarNo">
        <el-input
          v-model="queryParams.bookingOrderCarNo"
          placeholder="请输入车牌号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="订单号" prop="bookingOrderCode">
        <el-input
          v-model="queryParams.bookingOrderCode"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预约时间" prop="bookingOrderTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.bookingOrderTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择预约时间">
        </el-date-picker>
      </el-form-item>
     <!-- <el-form-item label="付款金额" prop="bookingOrderMoneys">
        <el-input
          v-model="queryParams.bookingOrderMoneys"
          placeholder="请输入付款金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="订单状态" prop="bookingOrderStatus">
        <el-select v-model="queryParams.bookingOrderStatus" placeholder="请选择预约单状态" clearable size="small">
			<el-option :value="0" label="未处理"></el-option>
			<el-option :value="1" label="已处理"></el-option>
			<el-option :value="2" label="处理中"></el-option>
        </el-select>
      </el-form-item>
     <!-- <el-form-item label="紧急电话" prop="bookingOrderEmergencyPhone">
        <el-input
          v-model="queryParams.bookingOrderEmergencyPhone"
          placeholder="请输入紧急电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
    <!--  <el-form-item label="经度" prop="bookingOrderLongitud">
        <el-input
          v-model="queryParams.bookingOrderLongitud"
          placeholder="请输入经度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="纬度" prop="bookingOrderLatitude">
        <el-input
          v-model="queryParams.bookingOrderLatitude"
          placeholder="请输入纬度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="车型" prop="bookingOrderVehicleModelId">
        <el-input
          v-model="queryParams.bookingOrderVehicleModelId"
          placeholder="请输入车型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
     <!-- <el-form-item label="车系" prop="bookingOrderVehicleId">
        <el-input
          v-model="queryParams.bookingOrderVehicleId"
          placeholder="请输入车系"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
     <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:order:add']"
        >新增</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:order:edit']"
        >修改</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:order:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:order:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="预约用户" align="center" prop="bookingOrderPid">
				<template slot-scope="scope">
					{{scope.row.personage.isTechnician !=null ? (scope.row.personage.isTechnician == 0 ? scope.row.personage.username:'是技师'):'暂无'}}
				</template>
			</el-table-column>
      <el-table-column label="技师" align="center" prop="bookingOrderPers">
				<template slot-scope="scope">
					{{scope.row.personage.isTechnician !=null ? (scope.row.personage.isTechnician == 1 ? scope.row.personage.username:'是用户'):'暂无'}}
				</template>
			</el-table-column>
      <el-table-column label="预约位置" align="center" prop="bookingOrderPath"  width="150"/>
      <el-table-column label="服务类型" align="center" prop="bookingOrderType" />
      <el-table-column label="车牌号" align="center" prop="bookingOrderCarNo" width="100"/>
      <el-table-column label="订单号" align="center" prop="bookingOrderCode" width="100"/>
      <el-table-column label="预约时间" align="center" prop="bookingOrderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bookingOrderTime, '{y}年{m}月{d} {h}时{m}分') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="付款金额(元)" align="center" prop="bookingOrderMoneys" width="100">
		  <template slot-scope="scope">
		  	{{scope.row.bookingOrderMoneys +'元'}}
		  </template>
	  </el-table-column>
      <el-table-column label="订单状态" align="center" prop="bookingOrderStatus">
		  <template slot-scope="scope">
		  		{{scope.row.bookingOrderStatus == 0 ? '未处理':(scope.row.bookingOrderStatus == 1 ? '已处理' : (scope.row.bookingOrderStatus==2 ? '处理中':'null'))}}
		  </template>
	  </el-table-column>
      <el-table-column label="备注" align="center" prop="bookingOrderContent" width="130"/>
      <el-table-column label="紧急电话" align="center" prop="bookingOrderEmergencyPhone" width="100"/>
      <el-table-column label="经度" align="center" prop="bookingOrderLongitud">
		  <template slot-scope="scope">
		  	{{scope.row.bookingOrderLongitud +'°'}}
		  </template>
	  </el-table-column>
      <el-table-column label="纬度" align="center" prop="bookingOrderLatitude">
		  <template slot-scope="scope">
		  	{{scope.row.bookingOrderLatitude +'°'}}
		  </template>
	  </el-table-column>
      <el-table-column label="车型" align="center" prop="bookingOrderVehicleModelId">
				<template slot-scope="scope">
					{{scope.row.vehicleModel.vehicleModelName}}
				</template>
			</el-table-column>
      <el-table-column label="车系" align="center" prop="bookingOrderVehicleId">
				<template slot-scope="scope">
					{{scope.row.vehicle.vehicleName}}
				</template>
			</el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"width="130">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:order:edit']"
          >修改</el-button>
		  
		  <el-dropdown trigger="click" size="mini">
		  			   <el-button
		  			     size="mini"
		  			     type="text"
		  			     class="el-dropdown-link">
		  			   更多操作<i class="el-icon-arrow-down el-icon--right"></i></el-button>
		        <el-dropdown-menu slot="dropdown">
		          <el-dropdown-item>
		  				 <el-button
		  				   size="mini"
		  				   type="text"
		  				   icon="el-icon-circle-check"
		  				   @click="handleUpdatee(scope.row)"
		  				   v-hasPermi="['system:orders:add']"
		  				 >去发货</el-button>
		  				 </el-dropdown-item>
		        </el-dropdown-menu>
		      </el-dropdown>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:order:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
		
			<!-- 添加或修改预约接单对话框 -->
			<el-dialog :title="title" :visible.sync="openss" width="500px" append-to-body>
			  <el-form ref="form" :model="form" :rules="rules" label-width="80px">
			    <el-form-item label="订单号" prop="bookingOrderCode">
			      <el-input v-model="form.bookingOrderCode" placeholder="请输入订单号" />
			    </el-form-item>
			  <!--  <el-form-item label="订单状态">
			        <el-select v-model="form.bookingOrderStatus" placeholder="请选择订单状态">
							<el-option :value="0" label="未处理"></el-option>
							<el-option :value="1" label="已处理"></el-option>
							<el-option :value="2" label="处理中"></el-option>
			      </el-select>
			    </el-form-item> -->
			  </el-form>
			  <div slot="footer" class="dialog-footer">
			    <el-button type="primary" @click="submitFormmm">确 定</el-button>
			    <el-button @click="cancell">取 消</el-button>
			  </div>
			</el-dialog>



    <!-- 添加或修改预约接单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
       <!-- <el-form-item label="预约订单" prop="bookingOrderId">
          <el-input v-model="form.bookingOrderId" placeholder="请输入预约单标识" />
        </el-form-item>
        <el-form-item label="预约用户" prop="bookingOrderPid">
          <el-input v-model="form.bookingOrderPid" placeholder="请输入预约用户—外键" />
        </el-form-item>
        <el-form-item label="技师" prop="bookingOrderPers">
          <el-input v-model="form.bookingOrderPers" placeholder="请输入技师—外键" />
        </el-form-item>
        <el-form-item label="预约位置" prop="bookingOrderPath">
          <el-input v-model="form.bookingOrderPath" placeholder="请输入预约位置" width="100"/>
        </el-form-item> -->
        <!-- <el-form-item label="服务类型">
          <el-select v-model="form.bookingOrderType" placeholder="请选择服务类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item> -->
       <!-- <el-form-item label="车牌号" prop="bookingOrderCarNo">
          <el-input v-model="form.bookingOrderCarNo" placeholder="请输入车牌号" />
        </el-form-item>
        <el-form-item label="订单号" prop="bookingOrderCode">
          <el-input v-model="form.bookingOrderCode" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="预约时间" prop="bookingOrderTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.bookingOrderTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择预约时间">
          </el-date-picker>
        </el-form-item> -->
        <!-- <el-form-item label="付款金额" prop="bookingOrderMoneys">
          <el-input v-model="form.bookingOrderMoneys" placeholder="请输入付款金额" />
        </el-form-item> -->
        <el-form-item label="订单状态">
            <el-select v-model="form.bookingOrderStatus" placeholder="请选择订单状态">
					<el-option :value="0" label="未处理"></el-option>
					<el-option :value="1" label="已处理"></el-option>
					<el-option :value="2" label="处理中"></el-option>
          </el-select>
        </el-form-item>
       <!-- <el-form-item label="备注" prop="bookingOrderContent">
          <el-input v-model="form.bookingOrderContent" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="紧急电话" prop="bookingOrderEmergencyPhone">
          <el-input v-model="form.bookingOrderEmergencyPhone" placeholder="请输入紧急电话" />
        </el-form-item>
        <el-form-item label="经度" prop="bookingOrderLongitud">
          <el-input v-model="form.bookingOrderLongitud" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="bookingOrderLatitude">
          <el-input v-model="form.bookingOrderLatitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="车型" prop="bookingOrderVehicleModelId">
          <el-input v-model="form.bookingOrderVehicleModelId" placeholder="请输入车型" />
        </el-form-item>
        <el-form-item label="车系" prop="bookingOrderVehicleId">
          <el-input v-model="form.bookingOrderVehicleId" placeholder="请输入车系" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder, exportOrder } from "@/api/system/bookingOrder";

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 预约接单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
	  openss:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bookingOrderId: undefined,
        bookingOrderPid: undefined,
        bookingOrderPers: undefined,
        bookingOrderPath: undefined,
        bookingOrderType: undefined,
        bookingOrderCarNo: undefined,
        bookingOrderCode: undefined,
        bookingOrderTime: undefined,
        bookingOrderMoneys: undefined,
        bookingOrderStatus: undefined,
        bookingOrderContent: undefined,
        bookingOrderEmergencyPhone: undefined,
        bookingOrderLongitud: undefined,
        bookingOrderLatitude: undefined,
        bookingOrderVehicleModelId: undefined,
        bookingOrderVehicleId: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询预约接单列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
	// 取消按钮
	cancell() {
	  this.openss = false;
	  this.reset();
	},
    // 表单重置
    reset() {
      this.form = {
        bookingOrderId: undefined,
        bookingOrderPid: undefined,
        bookingOrderPers: undefined,
        bookingOrderPath: undefined,
        bookingOrderType: undefined,
        bookingOrderCarNo: undefined,
        bookingOrderCode: undefined,
        bookingOrderTime: undefined,
        bookingOrderMoneys: undefined,
        bookingOrderStatus: "0",
        bookingOrderContent: undefined,
        bookingOrderEmergencyPhone: undefined,
        bookingOrderLongitud: undefined,
        bookingOrderLatitude: undefined,
        bookingOrderVehicleModelId: undefined,
        bookingOrderVehicleId: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.bookingOrderId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加预约接单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const bookingOrderId = row.bookingOrderId || this.ids
      getOrder(bookingOrderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改预约接单";
      });
    },
	/** 发货按钮操作 */
	handleUpdatee(row) {
	  this.reset();
	   const bookingOrderId = row.bookingOrderId || this.ids
	  getOrder(bookingOrderId).then(response => {
	    this.form = response.data;
	    this.openss = true;
	    this.title = "发货配件订单";
	  });
	},
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.bookingOrderId != undefined) {
            updateOrder(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addOrder(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
	/** 提交按钮 */
	submitFormmm: function() {
	  this.$refs["form"].validate(valid => {
	    if (valid) {
	      if (this.form.bookingOrderId != undefined) {
			   this.form.bookingOrderStatus = 2;
	        updateOrder(this.form).then(response => {
	          if (response.code === 200) {
	            this.msgSuccess("修改成功");
	            this.openss = false;
	            this.getList();
	          }
	        });
	      } else {
	        addOrder(this.form).then(response => {
	          if (response.code === 200) {
	            this.msgSuccess("新增成功");
	            this.openss = false;
	            this.getList();
	          }
	        });
	      }
	    }
	  });
	},
    /** 删除按钮操作 */
    handleDelete(row) {
      const bookingOrderIds = row.bookingOrderId || this.ids;
      this.$confirm('是否确认删除预约接单编号为"' + bookingOrderIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOrder(bookingOrderIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有预约接单数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportOrder(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>